package com.example.bobo.yuejian322.Activity;


import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.bobo.yuejian322.Adapter.PeixunAdapter;
import com.example.bobo.yuejian322.Adapter.Shaitu_comment_Adapter;
import com.example.bobo.yuejian322.Interfa.ShaituSeverice;
import com.example.bobo.yuejian322.R;
import com.example.bobo.yuejian322.base.BaseActivity;
import com.example.bobo.yuejian322.bean.ShaituDetial;
import com.squareup.picasso.Picasso;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class ShaituDetialActivity extends BaseActivity {
private ImageView pic1,pic2,pic3;
    private TextView clubname,intro,coment_number;
    private EditText edit;
    private Button button_sent;
     private ImageView back;
    private String saitu_id;
    private RecyclerView recyclerView;
    private Shaitu_comment_Adapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        saitu_id = getIntent().getStringExtra("Shaitu_id");
        setContentView(R.layout.activity_detial_shaitu);
        pic1= (ImageView) findViewById(R.id.pic1);
        pic2= (ImageView) findViewById(R.id.pic2);
        pic3= (ImageView) findViewById(R.id.pic3);
        clubname= (TextView) findViewById(R.id.club_sd);
        back= (ImageView) findViewById(R.id.shaitu_back);
        intro= (TextView) findViewById(R.id.intro_sd);
        coment_number= (TextView) findViewById(R.id.comen_sd);
        edit= (EditText) findViewById(R.id.edit_sd);
        button_sent= (Button) findViewById(R.id.button_sent_sd);
        recyclerView= (RecyclerView) findViewById(R.id.Detialshaitu_recyclerView);
        //返回
        back();
        //加载嗮图详情页数据
         data();

    }
//返回
    private void back(){

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


    }
    //加载嗮图详情页数据
    private  void data(){


        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.24.10.175/workout/api.php/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ShaituSeverice shaituSeverice =retrofit.create(ShaituSeverice.class);
        Call< List<ShaituDetial>> Listcall=shaituSeverice.shaitudetial(userId,1,saitu_id);
        Listcall.enqueue(new Callback<List<ShaituDetial>>() {
            @Override
            public void onResponse(Call<List<ShaituDetial>> call, Response<List<ShaituDetial>> response) {
                List<ShaituDetial> shaituDetial = response.body();
                if (ShaituDetialActivity.this != null){
                    //加载3张图片
                    if (shaituDetial.get(0).getThumb0()!="") {
                        Picasso.with(ShaituDetialActivity.this).load("http://172.24.10.175/workout/Uploads/"+shaituDetial.get(0).getThumb0()).error(R.drawable.image2).
                                into(pic1);
                    }
                    if (shaituDetial.get(0).getThumb0()!="") {
                        Picasso.with(ShaituDetialActivity.this).load("http://172.24.10.175/workout/Uploads/"+shaituDetial.get(0).getThumb1()).error(R.drawable.image1).
                                into(pic2);
                    }
                    if (shaituDetial.get(0).getThumb0()!="") {
                        Picasso.with(ShaituDetialActivity.this).load("http://172.24.10.175/workout/Uploads/"+shaituDetial.get(0).getThumb2()).error(R.drawable.image3).
                                into(pic3);
                    }
                    //加载其他控件数据
                    clubname.setText("#"+shaituDetial.get(0).getClub_name()+"#");
                    intro.setText(shaituDetial.get(0).getTitle());
                    coment_number.setText(shaituDetial.get(0).getHits());

                    //coment_number.setText(shaituDetial.get(0).getComment().size());

                    //shaituDetial.get(0).getComment();

                    adapter = new Shaitu_comment_Adapter(ShaituDetialActivity.this, shaituDetial.get(0).getComment());
                    LinearLayoutManager layoutManager = new LinearLayoutManager(getApplication());
                    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView.setLayoutManager(layoutManager);
                    recyclerView.setAdapter(adapter);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());


                }
            }
            @Override
            public void onFailure(Call<List<ShaituDetial>> call, Throwable t) {
                Toast.makeText(ShaituDetialActivity.this, "失败", Toast.LENGTH_SHORT).show();
            }
        });



    }

}
